package com.example.proxy.dynamic.jdk;

import com.example.proxy.dynamic.jdk.demo3.Man;
import sun.misc.ProxyGenerator;

import java.io.FileOutputStream;
import java.io.IOException;

public class Test$Proxy {

    public static void main(String[] args) {

        // 将产生的代理对象输出生成 class 文件，反编译进行查看，$Proxy0.class 这个 class 文件要先手动创建好
        String path = "D:/Workspaces/Tmp/java/$Proxy0.class";
        byte[] classFile = ProxyGenerator.generateProxyClass("$Proxy0", Man.class.getInterfaces());
        FileOutputStream out = null;
        try {
            out = new FileOutputStream(path);
            out.write(classFile);
            out.flush();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                out.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
